
(defclass %3ACLIPS_TOP_LEVEL_SLOT_CLASS "Fake class to save top-level slot information"
	(is-a USER)
	(role abstract)
	(multislot genere_preferit
		(type INSTANCE)
;+		(allowed-classes Genere)
		(create-accessor read-write))
	(single-slot pais_lec
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot dni
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot puntuacio_personal
		(type INTEGER)
		(range 0 10)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot pais_esc
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot internacional
		(type SYMBOL)
		(allowed-values FALSE TRUE)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot nom
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot KB_109530_Class28
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot format
		(type SYMBOL)
		(allowed-values de_butxaca gran)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot ha_escrit
		(type INSTANCE)
;+		(allowed-classes Llibre)
		(create-accessor read-write))
	(multislot ha_llegit
		(type INSTANCE)
;+		(allowed-classes Llibre_llegit)
		(create-accessor read-write))
	(single-slot tipus
		(type SYMBOL)
		(allowed-values divertit sexe violent predictible convencional masc0_fem10 duracio)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot sexe
		(type SYMBOL)
		(allowed-values masc fem)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot ref_llibre
		(type INSTANCE)
;+		(allowed-classes Llibre)
;+		(cardinality 1 1)
		(create-accessor read-write))
	(single-slot llegit_per
		(type INSTANCE)
;+		(allowed-classes Lector)
;+		(cardinality 1 1)
		(create-accessor read-write))
	(single-slot nom_genere
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot genere_esc_preferit
		(type INSTANCE)
;+		(allowed-classes Genere)
		(create-accessor read-write))
	(multislot genere
		(type INSTANCE)
;+		(allowed-classes Genere)
		(cardinality 1 ?VARIABLE)
		(create-accessor read-write))
	(single-slot genere_lec_preferit
		(type INSTANCE)
;+		(allowed-classes Genere)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot pagines
		(type INTEGER)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot best-seller
		(type SYMBOL)
		(allowed-values FALSE TRUE)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot titol
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot edat
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot te_caracteristica
		(type INSTANCE)
;+		(allowed-classes Caracteristica)
		(create-accessor read-write))
	(multislot autor_preferit
		(type INSTANCE)
;+		(allowed-classes Autor)
		(create-accessor read-write))
	(single-slot escrit_per
		(type INSTANCE)
;+		(allowed-classes Autor)
;+		(cardinality 1 1)
		(create-accessor read-write))
	(single-slot de_moda
		(type SYMBOL)
		(allowed-values FALSE TRUE)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot nota_tipus
		(type INTEGER)
		(range 0 10)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot critica
		(type INTEGER)
		(range 0 10)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot genere_semblant
		(type INSTANCE)
;+		(allowed-classes Genere)
		(create-accessor read-write)))

(defclass Lector
	(is-a USER)
	(role concrete)
	(single-slot pais_lec
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot genere_lec_preferit
		(type INSTANCE)
;+		(allowed-classes Genere)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot ha_llegit
		(type INSTANCE)
;+		(allowed-classes Llibre_llegit)
		(create-accessor read-write))
	(single-slot sexe
		(type SYMBOL)
		(allowed-values masc fem)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot edat
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot dni
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot autor_preferit
		(type INSTANCE)
;+		(allowed-classes Autor)
		(create-accessor read-write)))

(defclass Autor
	(is-a USER)
	(role concrete)
	(single-slot pais_esc
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot ha_escrit
		(type INSTANCE)
;+		(allowed-classes Llibre)
		(create-accessor read-write))
	(single-slot internacional
		(type SYMBOL)
		(allowed-values FALSE TRUE)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot nom
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot genere_esc_preferit
		(type INSTANCE)
;+		(allowed-classes Genere)
		(create-accessor read-write)))

(defclass Llibre
	(is-a USER)
	(role concrete)
	(multislot genere
		(type INSTANCE)
;+		(allowed-classes Genere)
		(cardinality 1 ?VARIABLE)
		(create-accessor read-write))
	(single-slot best-seller
		(type SYMBOL)
		(allowed-values FALSE TRUE)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot escrit_per
		(type INSTANCE)
;+		(allowed-classes Autor)
;+		(cardinality 1 1)
		(create-accessor read-write))
	(single-slot de_moda
		(type SYMBOL)
		(allowed-values FALSE TRUE)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot titol
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot critica
		(type INTEGER)
		(range 0 10)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot te_caracteristica
		(type INSTANCE)
;+		(allowed-classes Caracteristica)
		(create-accessor read-write))
	(single-slot format
		(type SYMBOL)
		(allowed-values de_butxaca gran)
;+		(cardinality 0 1)
		(create-accessor read-write)))

(defclass Genere
	(is-a USER)
	(role concrete)
	(single-slot nom_genere
		(type STRING)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(multislot genere_semblant
		(type INSTANCE)
;+		(allowed-classes Genere)
		(create-accessor read-write)))

(defclass Llibre_llegit
	(is-a USER)
	(role concrete)
	(single-slot puntuacio_personal
		(type INTEGER)
		(range 0 10)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot ref_llibre
		(type INSTANCE)
;+		(allowed-classes Llibre)
;+		(cardinality 1 1)
		(create-accessor read-write))
	(single-slot llegit_per
		(type INSTANCE)
;+		(allowed-classes Lector)
;+		(cardinality 1 1)
		(create-accessor read-write)))

(defclass Caracteristica
	(is-a USER)
	(role concrete)
	(single-slot tipus
		(type SYMBOL)
		(allowed-values divertit sexe violent predictible convencional masc0_fem10 duracio)
;+		(cardinality 0 1)
		(create-accessor read-write))
	(single-slot nota_tipus
		(type INTEGER)
		(range 0 10)
;+		(cardinality 0 1)
		(create-accessor read-write)))




(definstances instancies

([KB_109530_Class36] of  Lector

	(dni "123456789A")
	(edat "66")
	(ha_llegit [KB_109530_Class53])
	(pais_lec "ARG")
	(sexe masc))

([KB_109530_Class37] of  Genere

	(genere_semblant [KB_109530_Class38])
	(nom_genere "Ciencia Ficcio"))

([KB_109530_Class38] of  Genere

	(genere_semblant [KB_109530_Class37])
	(nom_genere "Futurista"))

([KB_109530_Class39] of  Genere

	(nom_genere "Terror"))

([KB_109530_Class40] of  Genere

	(nom_genere "Romanç"))

([KB_109530_Class41] of  Genere

	(nom_genere "Mitjaval"))

([KB_109530_Class42] of  Genere

	(nom_genere "Postapocaliptic"))

([KB_109530_Class44] of  Llibre

	(best-seller TRUE)
	(critica 8)
	(escrit_per [KB_109530_Class45])
	(genere [KB_109530_Class41])
	(titol "The Lord of the Rings I"))

([KB_109530_Class45] of  Autor

	(genere_esc_preferit [KB_109530_Class41])
	(ha_escrit [KB_109530_Class44])
	(internacional TRUE)
	(nom "J.R.R Tolkien")
	(pais_esc "UK"))

([KB_109530_Class46] of  Lector

	(autor_preferit [KB_109530_Class45])
	(dni "458613789B")
	(edat "23")
	(genere_lec_preferit [KB_109530_Class41])
	(ha_llegit [KB_109530_Class47])
	(pais_lec "ESP")
	(sexe masc))

([KB_109530_Class47] of  Llibre_llegit

	(llegit_per [KB_109530_Class46])
	(puntuacio_personal 7)
	(ref_llibre [KB_109530_Class44]))

([KB_109530_Class49] of  Autor

	(internacional TRUE)
	(nom "Gabriel García Márquez")
	(pais_esc "COL"))

([KB_109530_Class50] of  Autor

	(internacional TRUE)
	(nom "Alejandro Dumas")
	(pais_esc "FRA"))

([KB_109530_Class51] of  Autor

	(internacional TRUE)
	(nom "Victor Hugo")
	(pais_esc "FRA"))

([KB_109530_Class52] of  Llibre

	(escrit_per [KB_109530_Class51])
	(titol "Noventa y tres"))

([KB_109530_Class53] of  Llibre_llegit

	(llegit_per [KB_109530_Class36])
	(puntuacio_personal 8)
	(ref_llibre [KB_109530_Class52]))

([KB_109530_Class54] of  Lector

	(dni "876541298C")
	(edat "43")
	(pais_lec "ESP")
	(sexe fem))

([KB_109530_Class55] of  Lector

	(dni "732451159D")
	(edat "15")
	(pais_lec "ESP")
	(sexe fem))

([KB_109530_Class56] of  Lector

	(dni "976855199E")
	(edat "36")
	(pais_lec "FRA")
	(sexe masc))

([KB_109530_Class57] of  Autor

	(internacional TRUE)
	(nom "Stephen King")
	(pais_esc "USA"))

([KB_109530_Class58] of  Autor

	(internacional TRUE)
	(nom "Stephenie Meyer")
	(pais_esc "USA"))

([KB_109530_Class59] of  Autor

	(nom "Eduardo Mendoza")
	(pais_esc "ESP"))

([KB_109530_Class60] of  Autor

	(internacional TRUE)
	(nom "Emily Bronte")
	(pais_esc "UK"))

([KB_109530_Class61] of  Autor

	(internacional TRUE)
	(nom "Jane Austen")
	(pais_esc "UK"))

([KB_109530_Class62] of  Llibre

	(best-seller TRUE)
	(escrit_per [KB_109530_Class61])
	(titol "Orgullo y prejuicio"))

([KB_109530_Class63] of  Genere

	(nom_genere "Infantil"))

([KB_109530_Class64] of  Genere

	(nom_genere "Juvenil"))

)


;;;======================================================
;;;   Automotive Expert System
;;;
;;;     This expert system diagnoses some simple
;;;     problems with a car.
;;;
;;;     CLIPS Version 6.0 Example
;;;
;;;     To execute, merely load, reset and run.
;;;======================================================

;;****************
;;* DEFFUNCTIONS *
;;****************

(deffunction ask-question (?question $?allowed-values)
   (printout t ?question)
   (bind ?answer (read))
   (if (lexemep ?answer) 
       then (bind ?answer (lowcase ?answer)))
   (while (not (member ?answer ?allowed-values)) do
      (printout t ?question)
      (bind ?answer (read))
      (if (lexemep ?answer) 
          then (bind ?answer (lowcase ?answer))))
   ?answer)

(deffunction yes-or-no-p (?question)
   (bind ?response (ask-question ?question yes no y n))
   (if (or (eq ?response yes) (eq ?response y))
       then TRUE 
       else FALSE))

;;;**********************
;;;* ENGINE STATE RULES *
;;;**********************

(defrule normal-engine-state-conclusions ""
   (declare (salience 10))
   (working-state engine normal)
   =>
   (assert (repair "No repair needed."))
   (assert (spark-state engine normal))
   (assert (charge-state battery charged))
   (assert (rotation-state engine rotates)))

(defrule unsatisfactory-engine-state-conclusions ""
   (declare (salience 10))
   (working-state engine unsatisfactory)
   =>
   (assert (charge-state battery charged))
   (assert (rotation-state engine rotates)))

;;;***************
;;;* QUERY RULES *
;;;***************

(defrule determine-engine-state ""
   (not (working-state engine ?))
   (not (repair ?))
   =>
   (if (yes-or-no-p "Does the engine start (yes/no)? ") 
       then 
       (if (yes-or-no-p "Does the engine run normally (yes/no)? ")
           then (assert (working-state engine normal))
           else (assert (working-state engine unsatisfactory)))
       else 
       (assert (working-state engine does-not-start))))

(defrule determine-rotation-state ""
   (working-state engine does-not-start)
   (not (rotation-state engine ?))
   (not (repair ?))   
   =>
   (if (yes-or-no-p "Does the engine rotate (yes/no)? ")
       then
       (assert (rotation-state engine rotates))
       (assert (spark-state engine irregular-spark))
       else
       (assert (rotation-state engine does-not-rotate))       
       (assert (spark-state engine does-not-spark))))

(defrule determine-sluggishness ""
   (working-state engine unsatisfactory)
   (not (repair ?))
   =>
   (if (yes-or-no-p "Is the engine sluggish (yes/no)? ")
       then (assert (repair "Clean the fuel line."))))

(defrule determine-misfiring ""
   (working-state engine unsatisfactory)
   (not (repair ?))
   =>
   (if (yes-or-no-p "Does the engine misfire (yes/no)? ")
       then
       (assert (repair "Point gap adjustment."))       
       (assert (spark-state engine irregular-spark)))) 

(defrule determine-knocking ""
   (working-state engine unsatisfactory)
   (not (repair ?))
   =>
   (if (yes-or-no-p "Does the engine knock (yes/no)? ")
       then
       (assert (repair "Timing adjustment."))))

(defrule determine-low-output ""
   (working-state engine unsatisfactory)
   (not (symptom engine low-output | not-low-output))
   (not (repair ?))
   =>
   (if (yes-or-no-p "Is the output of the engine low (yes/no)? ")
       then
       (assert (symptom engine low-output))
       else
       (assert (symptom engine not-low-output))))

(defrule determine-gas-level ""
   (working-state engine does-not-start)
   (rotation-state engine rotates)
   (not (repair ?))
   =>
   (if (not (yes-or-no-p "Does the tank have any gas in it (yes/no)? "))
       then
       (assert (repair "Add gas."))))

(defrule determine-battery-state ""
   (rotation-state engine does-not-rotate)
   (not (charge-state battery ?))
   (not (repair ?))
   =>
   (if (yes-or-no-p "Is the battery charged (yes/no)? ")
       then
       (assert (charge-state battery charged))
       else
       (assert (repair "Charge the battery."))
       (assert (charge-state battery dead))))  

(defrule determine-point-surface-state ""
   (or (and (working-state engine does-not-start)      
            (spark-state engine irregular-spark))
       (symptom engine low-output))
   (not (repair ?))
   =>
   (bind ?response 
      (ask-question "What is the surface state of the points (normal/burned/contaminated)? "
                    normal burned contaminated))
   (if (eq ?response burned) 
       then 
      (assert (repair "Replace the points."))
       else (if (eq ?response contaminated)
                then (assert (repair "Clean the points.")))))

(defrule determine-conductivity-test ""
   (working-state engine does-not-start)      
   (spark-state engine does-not-spark)
   (charge-state battery charged)
   (not (repair ?))
   =>
   (if (yes-or-no-p "Is the conductivity test for the ignition coil positive (yes/no)? ")
       then
       (assert (repair "Repair the distributor lead wire."))
       else
       (assert (repair "Replace the ignition coil."))))

(defrule no-repairs ""
  (declare (salience -10))
  (not (repair ?))
  =>
  (assert (repair "Take your car to a mechanic.")))

;;;****************************
;;;* STARTUP AND REPAIR RULES *
;;;****************************

(defrule system-banner ""
  (declare (salience 10))
  =>
  (printout t crlf crlf)
  (printout t "The Engine Diagnosis Expert System")
  (printout t crlf crlf))

(defrule print-repair ""
  (declare (salience 10))
  (repair ?item)
  =>
  (printout t crlf crlf)
  (printout t "Suggested Repair:")
  (printout t crlf crlf)
  (format t " %s%n%n%n" ?item))

